home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / amidar.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  206 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *amidar_attributesram;
  15. static int flipscreen[2];
  16.  
  17.  
  18. static struct rectangle spritevisiblearea =
  19. {
  20.     2*8+1, 32*8-1,
  21.     2*8, 30*8-1
  22. };
  23. static struct rectangle spritevisibleareaflipx =
  24. {
  25.     0*8, 30*8-2,
  26.     2*8, 30*8-1
  27. };
  28.  
  29.  
  30.  
  31. /***************************************************************************
  32.  
  33.   Convert the color PROMs into a more useable format.
  34.  
  35.   Amidar has one 32 bytes palette PROM, connected to the RGB output this
  36.   way:
  37.  
  38.   bit 7 -- 220 ohm resistor  -- BLUE
  39.         -- 470 ohm resistor  -- BLUE
  40.         -- 220 ohm resistor  -- GREEN
  41.         -- 470 ohm resistor  -- GREEN
  42.         -- 1  kohm resistor  -- GREEN
  43.         -- 220 ohm resistor  -- RED
  44.         -- 470 ohm resistor  -- RED
  45.   bit 0 -- 1  kohm resistor  -- RED
  46.  
  47. ***************************************************************************/
  48. void amidar_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  49. {
  50.     int i;
  51.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  52.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  53.  
  54.  
  55.     for (i = 0;i < Machine->drv->total_colors;i++)
  56.     {
  57.         int bit0,bit1,bit2;
  58.  
  59.  
  60.         /* red component */
  61.         bit0 = (*color_prom >> 0) & 0x01;
  62.         bit1 = (*color_prom >> 1) & 0x01;
  63.         bit2 = (*color_prom >> 2) & 0x01;
  64.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  65.         /* green component */
  66.         bit0 = (*color_prom >> 3) & 0x01;
  67.         bit1 = (*color_prom >> 4) & 0x01;
  68.         bit2 = (*color_prom >> 5) & 0x01;
  69.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  70.         /* blue component */
  71.         bit0 = (*color_prom >> 6) & 0x01;
  72.         bit1 = (*color_prom >> 7) & 0x01;
  73.         *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  74.  
  75.         color_prom++;
  76.     }
  77.  
  78.  
  79.     /* characters and sprites use the same palette */
  80.     for (i = 0;i < TOTAL_COLORS(0);i++)
  81.     {
  82.         if (i & 3) COLOR(0,i) = i;
  83.         else COLOR(0,i) = 0;    /* 00 is always black, regardless of the contents of the PROM */
  84.     }
  85. }
  86.  
  87.  
  88.  
  89. WRITE_HANDLER( amidar_flipx_w )
  90. {
  91.     if (flipscreen[0] != (data & 1))
  92.     {
  93.         flipscreen[0] = data & 1;
  94.         memset(dirtybuffer,1,videoram_size);
  95.     }
  96. }
  97.  
  98. WRITE_HANDLER( amidar_flipy_w )
  99. {
  100.     if (flipscreen[1] != (data & 1))
  101.     {
  102.         flipscreen[1] = data & 1;
  103.         memset(dirtybuffer,1,videoram_size);
  104.     }
  105. }
  106.  
  107.  
  108.  
  109. WRITE_HANDLER( amidar_attributes_w )
  110. {
  111.     if ((offset & 1) && amidar_attributesram[offset] != data)
  112.     {
  113.         int i;
  114.  
  115.  
  116.         for (i = offset / 2;i < videoram_size;i += 32)
  117.             dirtybuffer[i] = 1;
  118.     }
  119.  
  120.     amidar_attributesram[offset] = data;
  121. }
  122.  
  123.  
  124.  
  125. /***************************************************************************
  126.  
  127.   Draw the game screen in the given osd_bitmap.
  128.   Do NOT call osd_update_display() from this function, it will be called by
  129.   the main emulation engine.
  130.  
  131. ***************************************************************************/
  132. void amidar_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  133. {
  134.     int offs;
  135.  
  136.  
  137.     /* for every character in the Video RAM, check if it has been modified */
  138.     /* since last time and update it accordingly. */
  139.     for (offs = videoram_size - 1;offs >= 0;offs--)
  140.     {
  141.         if (dirtybuffer[offs])
  142.         {
  143.             int sx,sy;
  144.  
  145.  
  146.             dirtybuffer[offs] = 0;
  147.  
  148.             sx = offs % 32;
  149.             sy = offs / 32;
  150.  
  151.             if (flipscreen[0]) sx = 31 - sx;
  152.             if (flipscreen[1]) sy = 31 - sy;
  153.  
  154.             drawgfx(tmpbitmap,Machine->gfx[0],
  155.                     videoram[offs],
  156.                     amidar_attributesram[2 * (offs % 32) + 1] & 0x07,
  157.                     flipscreen[0],flipscreen[1],
  158.                     8*sx,8*sy,
  159.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  160.         }
  161.     }
  162.  
  163.  
  164.     /* copy the temporary bitmap to the screen */
  165.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  166.  
  167.  
  168.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  169.     /* order, to have the correct priorities. */
  170.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  171.     {
  172.         int flipx,flipy,sx,sy;
  173.  
  174.  
  175.         sx = (spriteram[offs + 3] + 1) & 0xff;    /* ??? */
  176.         sy = 240 - spriteram[offs];
  177.         flipx = spriteram[offs + 1] & 0x40;
  178.         flipy = spriteram[offs + 1] & 0x80;
  179.  
  180.         if (flipscreen[0])
  181.         {
  182.             sx = 241 - sx;    /* note: 241, not 240 */
  183.             flipx = !flipx;
  184.         }
  185.         if (flipscreen[1])
  186.         {
  187.             sy = 240 - sy;
  188.             flipy = !flipy;
  189.         }
  190.  
  191.         /* Sprites #0, #1 and #2 need to be offset one pixel to be correctly */
  192.         /* centered on the ladders in Turtles (we move them down, but since this */
  193.         /* is a rotated game, we actually move them left). */
  194.         /* Note that the adjustement must be done AFTER handling flipscreen, thus */
  195.         /* proving that this is a hardware related "feature" */
  196.         if (offs <= 2*4) sy++;
  197.  
  198.         drawgfx(bitmap,Machine->gfx[1],
  199.                 spriteram[offs + 1] & 0x3f,
  200.                 spriteram[offs + 2] & 0x07,
  201.                 flipx,flipy,
  202.                 sx,sy,
  203.                 flipscreen[0] ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);
  204.     }
  205. }
  206.